/*
 * Copyright 2021 <copyright holder> <email>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef MAPPOINT_H
#define MAPPOINT_H

#include "common_include.h"
#include "feature.h"
#include "frame.h"

/**
 * @todo write docs
 */
class Mappoint
{
public:
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
    typedef std::shared_ptr<Mappoint> Ptr;
    unsigned long id_=0;
    bool is_outliner_=false;
    Vec3 pos_=Vec3::Zero();
    std::mutex data_mutex_;
    int observed_times_=0;
    std::list<std::weak_ptr<Feature>> observations_;
    
    Mappoint() {}
    Mappoint(long id, Vec3 position);
    
    Vec3 Pos() {
        std::unique_lock<std::mutex> lck(data_mutex_);
        return pos_;
    }
    
    void SetPos(const Vec3 &pos){
        std::unique_lock<std::mutex> lck(data_mutex_);
        pos_=pos;
    };
    
    void AddObservarion(std::shared_ptr<Feature> feature){
        std::unique_lock<std::mutex> lck(data_mutex_);
        observations_.push_back(feature);
        observed_times_++;
    }
    
    void RemoveObservation(std::shared_ptr<Feature> feat);
    
    std::list<std::weak_ptr<Feature>> GetObs(){
        std::unique_lock<std::mutex> lck(data_mutex_);
        return observations_;
    }
    
    
    static Mappoint::Ptr CreateNewMappoint();
};
#endif // MAPPOINT_H
